package com.albert.order.mq;

import com.albert.order.dao.OrderInfoMapper;
import com.albert.order.entry.OrderInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * @author yangjunwei
 * @date 2021/7/14 3:56 下午
 */
@Slf4j
@Component
public class MqConsumer {

    @Autowired
    OrderInfoMapper orderInfoMapper;

    @JmsListener(destination = "${scheduleMsg.topic}")
    public void receiveScheduleMsg(Integer orderId) {
        log.info("consumer msg =>{}", orderId);
        //对到期订单，开始检查
        OrderInfo orderInfo = orderInfoMapper.selectById(orderId);
        //订单未支付
        if (orderInfo.getOrderStatus() == 1) {
            //改为已过期
            orderInfo.setOrderStatus(4);
            orderInfoMapper.updateById(orderInfo);
            log.info("订单到期，从队列中取出的订单更新后为：{}", orderInfo);
        }
    }


}
